from flask import Flask, request
from 双色球 import 双色球开奖

app = Flask(__name__)


@app.route('/caipiao', methods=['GET'])
def indenx1():
    r = '''
    <div>
    <form action='/caipiao/ssq' method="post">
    <span>请输入注数：<span><input type='text' name='count'>
    <input type='submit' value='提交'>
    </form>
    </div>
    '''
    return r


@app.route('/caipiao/ssq', methods=['POST'])
def kaijiang():
    count = int(request.form['count'])
    x = 双色球开奖()
    ll = x.生成双色球号码(count)
    html = f'''
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    </head>
    <body>
    <div id='div'>
    </div>
    <script type='text/javascript'>
        var list1 = {ll};
        for(var i in list1){{
            var tag1 = document.createElement("span");
            var tag2 = document.createElement("span");
            tag1.style.width = "210px";
            tag1.style.display = "inline-block";
            var br = document.createElement("br");
            var ob = JSON.parse(list1[i]);
            console.log(ob);
            tag1.innerText = "红色：" + ob["hong"];
            tag2.innerText = " 蓝色：" + ob["lan"];
            document.getElementById("div").appendChild(tag1);
            document.getElementById("div").appendChild(tag2);
            document.getElementById("div").appendChild(br);
        }}
    </script>
    </body>
    </html>
    '''
    return html


if __name__ == '__main__':
    app.run()
